package cn.com.bluemoon.daps.model.controller.api;


import cn.com.bluemoon.daps.api.model.RemoteDapModelFieldRenameRecordService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.datascope.IgnorePermission;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.model.entity.DapDataModelFieldRenameRecord;
import cn.com.bluemoon.daps.model.service.DapDataModelFieldRenameRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = {"FeignClient服务-字段重命名记录服务"})
@RequestMapping(ServiceNameConstants.DapsApiModel.API_RENAME_RECORD)
@IgnorePermission(name = "字段重命名记录表")
@RestController
@Slf4j
public class DapDataModelFieldRenameRecordApi implements RemoteDapModelFieldRenameRecordService {

    @Resource
    DapDataModelFieldRenameRecordService dapDataModelFieldRenameRecordService;


    @GetMapping("/rename/record")
    @ApiOperation("查询字段重命名记录")
    public ResultBean<List<DapDataModelFieldRenameRecord>> renameRecordList(@RequestParam(value = "tableId") String tableId,
                                                           @RequestParam(value = "fieldId", required = false) String fieldId) {
        ResultBean<List<DapDataModelFieldRenameRecord>> renameRecord = dapDataModelFieldRenameRecordService.getRenameRecord(tableId, fieldId);
        return renameRecord;
    }

    @DeleteMapping("/delete/record")
    @ApiOperation("删除表改名记录")
    public ResultBean<String> deleteRecord(@RequestParam(value = "tableId") String tableId,
                             @RequestParam(value = "fieldId", required = false) String fieldId) {
        dapDataModelFieldRenameRecordService.deleteRenameRecord(tableId, fieldId);
        return ResultBean.ok("删除成功");
    }
}
